package com.ybwh.springboot2.satoken.controller;

import com.ybwh.springboot2.common.PageParam;
import com.ybwh.springboot2.common.Pagination;
import com.ybwh.springboot2.common.RespData;
import com.ybwh.springboot2.common.annotation.CurrUserId;
import com.ybwh.springboot2.satoken.model.entity.SysRole;
import com.ybwh.springboot2.satoken.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;




/**
 * <p>
 * 控制器
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2025-08-03 00:54:02
 */
@Slf4j
@Api(tags = "接口")
@RestController
@RequestMapping("/role")
public class SysRoleController{

    @Autowired
    private SysRoleService sysRoleService;


    @ApiOperation(value = "分页查询", notes = "")
    @ResponseBody
    @PostMapping("/getList")
    public RespData<Pagination<SysRole>> getList(@RequestBody PageParam<SysRole> pageParam) {

        Pagination<SysRole> page = sysRoleService.queryByPage(pageParam);
        return RespData.successResp(page);

    }


    @ApiOperation(value = "根据ID查询", notes = "")
    @ResponseBody
    @GetMapping("/queryById")
    public RespData<SysRole> queryById(@RequestParam("id") Long id) {

        SysRole sysRole = sysRoleService.getById(id);

        return RespData.successResp(sysRole);

    }


    @ApiOperation(value = "批量删除", notes = "")
    @ResponseBody
    @PostMapping("/batchDel")
    public RespData<Integer> batchDel(@RequestBody Set<Long> ids, @CurrUserId Long userId) {

        int effectCount = sysRoleService.deleteByIds(ids);

        return RespData.successResp(effectCount);

    }


    @ApiOperation(value = "新增或更新", notes = "")
    @ResponseBody
    @PostMapping("/addOrUpdate")
    public RespData<Long> addOrUpdate(@RequestBody SysRole param, @CurrUserId Long userId) {

        Long id =  sysRoleService.addOrUpdate(param,userId);

        return RespData.successResp(id);

    }


}
